import i18n from '@/lang'
import { strategyPerms } from '@/config/permission/index'
// 策略列表表头,列带有special属性值为true时，说时需要单独处理单元中的值
export const strategyTbColumns = [
  {
    title: i18n.t('policyName'),
    dataIndex: 'name',
    scopedSlots: { customRender: 'name' },
    special: true,
    width: 150
  }, {
    title: i18n.t('modelName'),
    dataIndex: 'modelName',
    scopedSlots: { customRender: 'modelName' },
    width: 150
  }, {
    title: i18n.t('smartDrivingDomainVersion'),
    dataIndex: 'vehicleVersionName',
    scopedSlots: { customRender: 'vehicleVersion' },
    special: true,
    width: 130
  }, {
    title: i18n.t('relatedECU'),
    dataIndex: 'ecuCount',
    scopedSlots: { customRender: 'relatedECU' },
    special: true,
    width: 100
  }, {
    title: i18n.t('policyStatus'),
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' },
    special: true,
    width: 100
  },
  //  {
  //   title: i18n.t('publishTime'),
  //   dataIndex: 'publishTime',
  //   scopedSlots: { customRender: 'publishTime' },
  //   width: 120,
  //   sorter: true
  // },
   {
    title: i18n.t('timeOfCreation'),
    dataIndex: 'createTime',
    scopedSlots: { customRender: 'createTime' },
    width: 160,
    sorter: true
  }, {
    title: i18n.t('creator'),
    dataIndex: 'createBy',
    scopedSlots: { customRender: 'createBy' },
    width: 100
  }, {
    title: i18n.t('operation'),
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    special: true,
    width: 500,
    fixed: 'right'
  }]

export const strategyTbRowAction = [
  {
    title: i18n.t('edit') + i18n.t('strategy'),
    key: 'editStrategy',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.edit
    },
    disabled (record) {
      // 如果是升级策略当不是待测试时或者停用时不能再编辑
      return record.status !== 1 || !record.enabled
    }
  },
  {
    title: i18n.t('delete') + i18n.t('strategy'),
    key: 'deleteList',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.delete
    },
    disabled (record) {
      // 如果是升级策略当不是待测试时不能删除,停用时能删除
      return record.enabled && record.status !== 1
    }
  },
  {
    title: i18n.t('new') + i18n.t('test'),
    key: 'createTest',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.createTest
    },
    disabled (record) {
      // 是升级策略时状态为停用状态不可用或者审核中时不可用,已发布也不能新建测试
      return !record.enabled || record.status === 6 || record.status === 9
    }
  },
  {
    title: i18n.t('view') + i18n.t('test'),
    key: 'lookupTest',
    disabled (record) {
      // 是升级策略时状态为待测试时不可用
      return record.status === 1
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.viewTest
    }
  },
  {
    title: i18n.t('publishPolicy'),
    key: 'publishStrategy',
    disabled (record, vm) {
      // 是升级策略时状态为未被停用且测试中才能使用
      return vm.versionType === 'TEST' || !(record.enabled && record.status === 2)
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.publish
    }
  },
  // 停用策略
  {
    title: i18n.t('disabled') + i18n.t('strategy'),
    key: 'disabledStrategy',
    disabled (record) {
      // 已停用了的则不显示
      return !record.enabled
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.disabled
    }
  },
  // 启用策略
  {
    title: i18n.t('start') + i18n.t('strategy'),
    key: 'enabledStrategy',
    disabled (record) {
      // 已停用了的则显示
      return record.enabled
    },
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.disabled
    }
  },
  // 复制策略
  {
    title: i18n.t('copy') + i18n.t('strategy'),
    key: 'copyStrategy',
    getAuth (record, vm) {
      return strategyPerms[vm.versionType][vm.upgradeTriggerType].fotaSjcl.copy
    }
  }

]

// 场景前置条件表头
export const strategySceneTbColumns = [
  {
    title: i18n.t('updateScene'),
    dataIndex: 'type',
    scopedSlots: { customRender: 'scene' },
    width: 180
  },
  {
    title: i18n.t('fdjState'),
    dataIndex: 'engine_status',
    scopedSlots: { customRender: 'fdjState' },
    width: 220,
    align: 'center'
  },
  {
    title: i18n.t('dcdy') + '(V)',
    dataIndex: 'battery_voltage_limit',
    scopedSlots: { customRender: 'dcdy' },
    align: 'center'
  },
  {
    title: i18n.t('zddcdl') + '(%)',
    dataIndex: 'battery_percent_limit',
    scopedSlots: { customRender: 'zddcdl' },
    width: 220,
    align: 'center'
  }
]

// 升级策略选择软件表头
export const strategyPartColumns = [
  {
    title: i18n.t('versionSelection'),
    dataIndex: 'selectedVersion',
    scopedSlots: { customRender: 'versionSelection' },
    width: '15%'
  },
  {
    title: i18n.t('partNumber'),
    dataIndex: 'partNumber',
    scopedSlots: { customRender: 'partNumber' }
  },
  {
    title: i18n.t('partName'),
    dataIndex: 'name',
    scopedSlots: { customRender: 'partName' }
  },
  {
    title: i18n.t('sbcl'),
    dataIndex: 'versionGroupRollback',
    scopedSlots: { customRender: 'sbcl' }
  },
  {
    title: i18n.t('softDid'),
    dataIndex: 'softwareDid',
    scopedSlots: { customRender: 'softDid' }
  },
  {
    title: i18n.t('diagnosis') + 'ID',
    dataIndex: 'nodeAddress',
    scopedSlots: { customRender: 'diagnosis' }
  },
  {
    title: i18n.t('updateOrder'),
    dataIndex: 'updateOrder',
    scopedSlots: { customRender: 'updateOrder' },
    width: 100
  },
  {
    title: i18n.t('OS'),
    dataIndex: 'platform',
    scopedSlots: { customRender: 'OS' }
  },
  {
    title: i18n.t('releaseNote'),
    dataIndex: 'releaseNotes',
    scopedSlots: { customRender: 'releaseNote' }
  }
]

// 新建测试时选择车辆表头
export const strategyTestVehicleColumns = [
  {
    title: 'VIN',
    dataIndex: 'vin',
    scopedSlots: { customRender: 'vin' },
    width: 150
  },
  {
    title: i18n.t('usage'),
    dataIndex: 'taskOccupied',
    scopedSlots: { customRender: 'usage' },
    width: 100
  },
  {
    title: i18n.t('brandName'),
    dataIndex: 'brandName',
    scopedSlots: { customRender: 'brandName' },
    width: 150
  },
  {
    title: i18n.t('modelCode'),
    dataIndex: 'modelCode',
    scopedSlots: { customRender: 'modelCode' },
    width: 150
  },
  {
    title: i18n.t('modelName'),
    dataIndex: 'modelName',
    scopedSlots: { customRender: 'model' },
    width: 150
  },
  {
    title: i18n.t('stereotype'),
    dataIndex: 'trimLevel',
    scopedSlots: { customRender: 'stereotype' },
    width: 100
  },
  {
    title: i18n.t('province'),
    dataIndex: 'province',
    scopedSlots: { customRender: 'province' },
    width: 100
  },
  {
    title: i18n.t('timeOfCreation'),
    dataIndex: 'createTime',
    scopedSlots: { customRender: 'timeOfCreation' },
    width: 160,
    sorter: true
  }
]
// 新建测试时版本声明表头
export const explainsColumns= [
  {
    title: i18n.t('功能描述标题'),
    dataIndex: 'functionTitle',
    width:80,
    key: 'functionTitle',
    scopedSlots: { customRender: 'functionTitle' },
  },
  {
    title: i18n.t('功能描述内容'),
    dataIndex: 'functionMsg',
    key: 'functionMsg',
    width:180,
    scopedSlots: { customRender: 'functionMsg' }
  },
  {
    title: i18n.t('operation'),
    dataIndex: 'operation',
    width:30,
    scopedSlots: { customRender: 'operation' },
  }
]

// 查看测试时测试车辆表头
export const strategyViewTestVehicleColumns = [
  {
    title: 'VIN',
    dataIndex: 'vin',
    scopedSlots: { customRender: 'vin' },
    width: 180
  },
  {
    title: '升级结果',
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' },
    width: 120
  },
  // {
  //   title: i18n.t('taskVehicleAppointTime'),
  //   dataIndex: 'taskVehicleAppointTimeList',
  //   scopedSlots: { customRender: 'taskVehicleAppointTimeList' },
  //   width: 180
  // },
  {
    title: i18n.t('resendTimes'),
    dataIndex: 'factoryRetryCount',
    scopedSlots: { customRender: 'factoryRetryCount' },
    width: 120
  },
  {
    title: i18n.t('failedNumber'),
    dataIndex: 'upgradeFailNum',
    scopedSlots: { customRender: 'upgradeFailNum' },
    width: 120
  },
  {
    title: i18n.t('vehicleStartTime'),
    dataIndex: 'startTime',
    scopedSlots: { customRender: 'startTime' },
    width: 160,
    sorter: true
  },
  {
    title: i18n.t('ztgsTime'),
    dataIndex: 'updateTime',
    scopedSlots: { customRender: 'updateTime' },
    width: 160,
    sorter: true
  },
  // {
  //   title: i18n.t('czzt'),
  //   dataIndex: 'upgradeStatus',
  //   scopedSlots: { customRender: 'upgradeStatus' },
  //   width: 100
  // },
  // {
  //   title: i18n.t('modelName'),
  //   dataIndex: 'modelName',
  //   scopedSlots: { customRender: 'vehicleModel' },
  //   width: 140
  // },
  // {
  //   title: i18n.t('stereotype'),
  //   dataIndex: 'trimLevel',
  //   scopedSlots: { customRender: 'stereotype' },
  //   width: 120
  // },
  {
    title: i18n.t('operation'),
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    width: 100,
    fixed: 'right'
  }
]

// 查看某任务下某车辆的零件升级表格表头
export const strategyTestVehiclePartUpdateColumns = [
  {
    title: i18n.t('partNumber'),
    dataIndex: 'partNumber',
    scopedSlots: { customRender: 'partNumber' },
    width: 220
  },
  {
    title: i18n.t('partName'),
    dataIndex: 'ecuName',
    scopedSlots: { customRender: 'partName' }
  },
  {
    title: i18n.t('originalVersion'),
    dataIndex: 'sourceVersionName',
    scopedSlots: { customRender: 'originalVersion' }
  },
  {
    title: i18n.t('targetVersion'),
    dataIndex: 'targetVersionName',
    scopedSlots: { customRender: 'targetVersion' }
  },
  {
    title: i18n.t('status'),
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' },
    width: 120
  }
]

// 查看条件策略绑定的任务表表头
export const strategyTaskColumns = [
  {
    title: i18n.t('campaignName'),
    dataIndex: 'name',
    scopedSlots: { customRender: 'name' }
  },
  {
    title: i18n.t('start') + i18n.t('time'),
    dataIndex: 'startTime',
    scopedSlots: { customRender: 'startTime' },
    width: 200
  },
  {
    title: i18n.t('expirationDate'),
    dataIndex: 'endTime',
    scopedSlots: { customRender: 'endTime' }
  },
  {
    title: i18n.t('campaignStatus'),
    dataIndex: 'status',
    scopedSlots: { customRender: 'status' },
    width: 120
  }
]

// 选择分组中表头
export const strategyVersionGroupColumns = [
  {
    title: i18n.t('partNumber'),
    dataIndex: 'partNumber',
    scopedSlots: { customRender: 'partNumber' }
  },
  {
    title: i18n.t('partName'),
    dataIndex: 'partName',
    scopedSlots: { customRender: 'partNumber' }
  },
  {
    title: i18n.t('softDid'),
    dataIndex: 'softwareDid',
    scopedSlots: { customRender: 'softwareDid' }
  },
  {
    title: i18n.t('versionName'),
    dataIndex: 'versionName',
    scopedSlots: { customRender: 'versionName' }
  }
]

// 查看测试只更多统计信息列表表头,amountTo是否要参与合计
export const moreTestMoreStatisticColumns = [
  {
    title: i18n.t('testBatch'),
    dataIndex: 'testBatch',
    scopedSlots: { customRender: 'testBatch' },
    width: '8%'
  },
  {
    title: i18n.t('allVehicles'),
    dataIndex: 'allVehicles',
    scopedSlots: { customRender: 'allVehicles' },
    width: '12%',
    amountTo: true
  },
  {
    title: i18n.t('successfulVehicle'),
    dataIndex: 'successfulVehicle',
    scopedSlots: { customRender: 'successfulVehicle' },
    width: '8%',
    amountTo: true
  },
  {
    title: i18n.t('failedVehicle'),
    dataIndex: 'failedVehicle',
    scopedSlots: { customRender: 'failedVehicle' },
    width: '8%',
    amountTo: true
  },
  {
    title: i18n.t('vehicleInProgress'),
    dataIndex: 'vehicleInProgress',
    scopedSlots: { customRender: 'vehicleInProgress' },
    width: '15%',
    amountTo: true
  },
  {
    title: i18n.t('vehicleNotStarted'),
    dataIndex: 'vehicleNotStarted',
    scopedSlots: { customRender: 'vehicleNotStarted' },
    width: '15%',
    amountTo: true
  },
  {
    title: i18n.t('suspendedVehicle'),
    dataIndex: 'suspendedVehicle',
    scopedSlots: { customRender: 'suspendedVehicle' },
    width: '11%',
    amountTo: true
  },
  {
    title: i18n.t('unfinishedVehicle'),
    dataIndex: 'unfinishedVehicle',
    scopedSlots: { customRender: 'unfinishedVehicle' },
    width: '15%',
    amountTo: true
  },
  {
    title: i18n.t('averageTime'),
    dataIndex: 'averageTime',
    scopedSlots: { customRender: 'averageTime' },
    width: '8%',
    amountTo: true
  }
]
// SOTA升级策略选择应用版本表头
export const sotaStrategyAppVersionColumns = [
  {
    title: i18n.t('sotaApp'),
    dataIndex: 'softwareName',
    scopedSlots: { customRender: 'versionSelection' },
    width: '15%'
  },
  {
    title: i18n.t('partNumber'),
    dataIndex: 'partNumber',
    scopedSlots: { customRender: 'partNumber' },
    width: '20%'
  },
  {
    title: i18n.t('partName'),
    dataIndex: 'name',
    scopedSlots: { customRender: 'partName' },
    width: '20%'
  },
  {
    title: i18n.t('versionName'),
    dataIndex: 'versionName',
    scopedSlots: { customRender: 'versionName' },
    width: '15%'
  },
  {
    title: i18n.t('versionCode'),
    dataIndex: 'versionCode',
    scopedSlots: { customRender: 'versionCode' },
    width: '15%'
  },
  {
    title: i18n.t('releaseNote'),
    dataIndex: 'releaseNotes',
    scopedSlots: { customRender: 'releaseNote' },
    width: '10%'
  }
]
